package com.mjh.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mjh.bean.ClueRemark;
import com.mjh.mapper.ClueRemarkMapper;
import com.mjh.service.ClueRemarkService;
import com.mjh.utils.AuthUtil;
import com.mjh.vo.ClueRemarkVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ClueRemarkServiceImpl implements ClueRemarkService {
    @Autowired
    private ClueRemarkMapper clueRemarkMapper;
    @Override
    public PageInfo<ClueRemarkVo> queryClueRemarkListByPage(Integer current, Integer size, Integer clueId) {
        PageHelper.startPage(current,size);
        List<ClueRemarkVo> list = clueRemarkMapper.selectListByClueId(clueId);
        return new PageInfo<>(list);
    }

    @Override
    public Boolean saveClueRemark(ClueRemark clueRemark) {
        clueRemark.setCreateBy(AuthUtil.getLoginUserId());
        clueRemark.setCreateTime(new Date());
        clueRemark.setDeleted(0);
        return clueRemarkMapper.insertSelective(clueRemark)>0;
    }

    @Override
    public ClueRemark queryClueRemarkInfoById(Integer id) {
        return clueRemarkMapper.selectByPrimaryKey(Long.valueOf(id));
    }

    @Override
    public Boolean modifyClueRemark(ClueRemark clueRemark) {
        clueRemark.setEditBy(AuthUtil.getLoginUserId());
        clueRemark.setEditTime(new Date());
        return clueRemarkMapper.updateByPrimaryKeySelective(clueRemark)>0;
    }

    @Override
    public Boolean removeClueRemarkById(Integer id) {
        ClueRemark clueRemark = new ClueRemark();
        clueRemark.setId(id);
        clueRemark.setDeleted(1);
        clueRemark.setEditTime(new Date());
        clueRemark.setEditBy(AuthUtil.getLoginUserId());
        return clueRemarkMapper.updateByPrimaryKeySelective(clueRemark)>0;
    }
}
